﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Anchor : MonoBehaviour
{
        [Header("所在的区域编号")]
        public int area;
        [Header("所在区域内的ID")]
        public int id = 0;

        [Header("描述文本")]
        public TextMesh description;

        Range[] range;

        void Awake()
        {
                //查找区域子对象
                range = this.GetComponentsInChildren<Range>();
        }

        void Start()
        {
                this.transform.gameObject.SetActive(false);
        }

        public void SetAnchor(Vec3dInfo ver)
        {
                if (description != null)
                {
                        //设置描述
                        string des = "  锚点" + (id + 1) + ":<color=blue>(" + ver.x.ToString("f2") + "," + ver.y.ToString("f2") + "," + ver.z.ToString("f2") + ")</color>";
                        description.text = des;
                }

                //设置自身坐标
                //this.transform.position = XYZTranslate.GetXYZ(area, ver);
                this.transform.localPosition = XYZTranslate.GetLocalXYZ(ver);
                this.transform.gameObject.SetActive(true);
        }

        public void SetAnchor(Vec3dInfo ver, double n)
        {
                //设置坐标
                this.SetAnchor(ver);

                if (range[0] != null)
                {
                        //设置区域的半径
                        range[0].SetRange(n);
                }
        }
}
